package com.ce.pms.customer.service.impl;



import java.util.ArrayList;
import java.util.List;

import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.common.annotation.AssociatedBuildingQuery;
import com.ce.pms.customer.dao.ICustomerDao;
import com.ce.pms.customer.service.IHisResidentService;
import com.ce.pms.customer.vo.CustListVO;
import com.ce.pms.customer.vo.CustSearchVO;
import com.ce.pms.house.dao.IHouseDao;
import com.sitechasia.webx.core.support.Page;

/**
*
* 功能描述: 居住历史查询Service
*
* <p>
* 版权所有：中企动力
* <p>
* 未经本公司许可，不得以任何方式复制或使用本程序任何部分
*
* @author <a href="malto:szyandawei@myce.net.cn">燕大为</a>
* Created on 2008-5-22
*
*/
public class HisResidentServiceImpl extends PmsBaseServiceImpl implements IHisResidentService {

	protected ICustomerDao customerDao;

	protected IHouseDao houseDao;

	/***
	 * Function: 居住历史查询方法
	 * @param custSearch 查询条件
	 * @param pageNO   查询第多少页
	 * @param pageSize 每页显示记录数
	 * @return page 查询结果集
	 * Create author:燕大为
	 * Create on:2008-6-6
	 * Edit author: 黄腾飞
	 * Edit on: annotation
	 * Why: aop
	 */
	public Page queryHisresInfo(CustSearchVO custSearch, int pageNO, int pageSize) {
		custSearch.setHouseIds(houseDao.getHouseIdByNumber(custSearch.getHouseNumber()) );
		if(isNotFoundHouseByHouseNumber(custSearch) ){
			return new Page();
		}
		Page page = customerDao.queryHisResidents(custSearch, pageNO, pageSize);
		page.setResult(converObjectToVO(page.getResult()));
		return page;
	}

	/**
	 * 功能描述:如果输入的房号不存在，则返回真<br>
	 * @param vo
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-21<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private boolean isNotFoundHouseByHouseNumber(CustSearchVO vo) {
		return null!=vo.getHouseNumber() && vo.getHouseNumber().trim().length()>0 &&
				( null==vo.getHouseIds() || vo.getHouseIds().trim().length()<=0);
	}
	/**
	 *
	* Function:将查询的数组转换为显示VO
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-11
	* Edit author:
	* Edit on:
	* Why:
	 */
	private List<CustListVO> converObjectToVO(List<Object[]> residentList){
		List<CustListVO> tempList = new ArrayList<CustListVO>();
		CustListVO custListVO = null;
		for (Object[] item : residentList) {
			custListVO = new CustListVO();
			custListVO.setHouseNumber((String)item[0]);
			custListVO.setCustomerName((String)item[1]);
			custListVO.setCustomerType((String)item[2]);
			if(item[3] != null) {
				custListVO.setInDate(item[3].toString());
			}
			if(item[4] != null) {
				custListVO.setOutDate(item[4].toString());
			}
			custListVO.setIdType((String)item[5]);//证件名
			custListVO.setIdNO((String)item[6]);
			custListVO.setTelephone((String)item[7]);
			if(item[11] != null ) {
				custListVO.setParticipantId(Long.valueOf(item[11].toString()));
			}
			tempList.add(custListVO);
		}
		return tempList;
	}

	public void setCustomerDao(ICustomerDao customerDao) {
		this.customerDao = customerDao;
	}

	public void setHouseDao(IHouseDao houseDao) {
		this.houseDao = houseDao;
	}

}
